package org.jeecg.modules.workflow.convert.oa;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.workflow.vo.oa.BpmOALeaveCreateReqVO;
import org.jeecg.common.workflow.vo.oa.BpmOALeaveRespVO;
import org.jeecg.modules.workflow.entity.BpmOaLeave;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class BpmOALeaveConvertImpl implements BpmOALeaveConvert {

    @Override
    public BpmOaLeave convert(BpmOALeaveCreateReqVO bean) {
        if ( bean == null ) {
            return null;
        }

        BpmOaLeave bpmOALeaveDO = new BpmOaLeave();

        if ( bean.getType() != null ) {
            bpmOALeaveDO.setType(bean.getType());
        }
        bpmOALeaveDO.setReason( bean.getReason() );
        bpmOALeaveDO.setStartTime( bean.getStartTime() );
        bpmOALeaveDO.setEndTime( bean.getEndTime() );

        return bpmOALeaveDO;
    }

    @Override
    public BpmOALeaveRespVO convert(BpmOaLeave bean) {
        if ( bean == null ) {
            return null;
        }

        BpmOALeaveRespVO bpmOALeaveRespVO = new BpmOALeaveRespVO();

        bpmOALeaveRespVO.setStartTime( bean.getStartTime() );
        bpmOALeaveRespVO.setEndTime( bean.getEndTime() );
        if ( bean.getType() != null ) {
            bpmOALeaveRespVO.setType( bean.getType());
        }
        bpmOALeaveRespVO.setReason( bean.getReason() );
        bpmOALeaveRespVO.setId( bean.getId() );
        bpmOALeaveRespVO.setResult( bean.getResult() );
        bpmOALeaveRespVO.setCreateTime( bean.getCreateTime() );
        bpmOALeaveRespVO.setProcessInstanceId( bean.getProcessInstanceId() );

        return bpmOALeaveRespVO;
    }

    @Override
    public List<BpmOALeaveRespVO> convertList(List<BpmOaLeave> list) {
        if ( list == null ) {
            return null;
        }

        List<BpmOALeaveRespVO> list1 = new ArrayList<BpmOALeaveRespVO>( list.size() );
        for ( BpmOaLeave bpmOALeaveDO : list ) {
            list1.add( convert( bpmOALeaveDO ) );
        }

        return list1;
    }

    @Override
    public IPage<BpmOALeaveRespVO> convertPage(IPage<BpmOaLeave> page) {
        if ( page == null ) {
            return null;
        }

        IPage<BpmOALeaveRespVO> pageResult = new Page<>();

        pageResult.setRecords( convertList( page.getRecords() ) );
        pageResult.setTotal( page.getTotal() );

        return pageResult;
    }
}
